package lanou.autohome.recommend.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import lanou.autohome.basetool.NetTool;
import lanou.autohome.R;
import lanou.autohome.recommend.beans.BulletinBean;

/**
 * Created by dllo on 16/8/15.
 * 推荐 -> 快报
 */
public class BulletinAdapter extends RecyclerView.Adapter<BulletinAdapter.KuaiViewHolder>{

    private Context mcontext;
    private BulletinBean aLists;

    public BulletinAdapter(Context mcontext) {
        this.mcontext = mcontext;
    }

    public void setaLists(BulletinBean aLists) {
        this.aLists = aLists;
    }

    @Override
    public BulletinAdapter.KuaiViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mcontext).inflate(R.layout.item_recommend_bulletin, null);
        KuaiViewHolder kuaiViewHolder = new KuaiViewHolder(view);

        return kuaiViewHolder;
    }

    @Override
    public void onBindViewHolder(BulletinAdapter.KuaiViewHolder holder, int position) {
        BulletinBean.ResultBean.ListBean bean = aLists.getResult().getList().get(position);


        String str = String.valueOf(bean.getReviewcount());
        holder.title.setText(aLists.getResult().getList().get(position).getTitle());
        holder.createtime.setText(aLists.getResult().getList().get(position).getCreatetime());
        holder.reviewcount.setText(str + "人浏览");

//        Picasso.with(mcontext).load(aLists.getResult().getList().get(position).getImg()).into(holder.img);
        NetTool netTool = new NetTool();
        netTool.getImage(bean.getImg(),holder.img);
    }

    @Override
    public int getItemCount() {
        return aLists != null ?aLists.getResult().getList().size() : 0;
    }


    public class KuaiViewHolder extends RecyclerView.ViewHolder {
        TextView title;
        ImageView img;
        TextView createtime;
        TextView reviewcount;
        public KuaiViewHolder(View itemView) {
            super(itemView);
            title = (TextView) itemView.findViewById(R.id.title_recommend_bulletin_item);
            img = (ImageView) itemView.findViewById(R.id.img_recommend_bulletin_item);
            createtime = (TextView) itemView.findViewById(R.id.createtime_recommend_bulletin_item);
            reviewcount = (TextView) itemView.findViewById(R.id.reviewcount_recommend_bulletin_item);
        }
    }
}
